package serverdata.ch.home.www.ResponseClass;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import serverdata.ch.home.www.R;
import serverdata.ch.home.www.SensorCoding.SENSORI;
import serverdata.ch.home.www.server.HttpData;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;

public class IndexPage {


	public IndexPage(PrintWriter out, BufferedReader in, Context context) throws IOException {

		
		StringBuilder data = new StringBuilder();
		InputStream index = context.getResources().openRawResource(R.raw.index);
		BufferedReader bd = new BufferedReader(new InputStreamReader(index));
		while(bd.ready()){
			data.append(bd.readLine());
		}
		/*data.append("<html><title>Dati andorid</title><body>");
		
		
		data.append("<h1>"+"<a href=\"getallsensorExisting"+"\">Dammi tutti i sensori disponibili</a></h1>" );
			
		
		data.append("<form action=\"getsensorvalues\">");
		data.append("<input type=\"submit\" value=\"submit\">");
		data.append("<select>");
		data.append("<option name=\"sensore\" value=\"volvo\">Volvo</option>");
		data.append("</select>");
		data.append("</form>");
		
		data.append("</body></html>");
		*/

		out.print(HttpData.createHeaderHTTP(data.toString(), 200, "html"));

		out.print(data.toString()+"\r\n");
		out.flush();
		out.close();
		in.close();
	
		
	
	}
	
	
	public static List<String> getSensorName(SensorManager sm){
		
		List<Sensor> lista = sm.getSensorList(Sensor.TYPE_ALL);
		
		List<String> sensorname = new ArrayList<String>();
		
		for(Sensor sensore : lista){
			switch(sensore.getType()){
			case Sensor.TYPE_ACCELEROMETER:
				sensorname.add(SENSORI.ACC.toString());
				break;
			case Sensor.TYPE_GRAVITY:
				sensorname.add(SENSORI.GRAV.toString());
				break;
			case Sensor.TYPE_GYROSCOPE:
				sensorname.add(SENSORI.GYRO.toString());
				break;
			case Sensor.TYPE_LIGHT:
				sensorname.add(SENSORI.LIGHT.toString());
				break;
			case Sensor.TYPE_LINEAR_ACCELERATION:
				sensorname.add(SENSORI.LINACC.toString());
				break;
			case Sensor.TYPE_MAGNETIC_FIELD:
				sensorname.add(SENSORI.MAG.toString());
				break;
			case Sensor.TYPE_ORIENTATION:
				sensorname.add(SENSORI.ORIENT.toString());
				break;
			case Sensor.TYPE_PRESSURE:
				sensorname.add(SENSORI.PRESS.toString());
				break;
			case Sensor.TYPE_PROXIMITY:
				sensorname.add(SENSORI.PROX.toString());
				break;
			case Sensor.TYPE_ROTATION_VECTOR:
				sensorname.add(SENSORI.ROTA.toString());
				break;
			case Sensor.TYPE_TEMPERATURE:
				sensorname.add(SENSORI.TEMP.toString());
				break;
			}
		}
		return sensorname;
	}


}
